<?php

namespace App\Utility;

use EasySwoole\Component\Singleton;
use EasySwoole\HttpClient\Exception\InvalidUrl;
use EasySwoole\HttpClient\HttpClient;

/**
 * 蓝卡
 */
class BlueCard
{
    use Singleton;

    /**
     * md5加密
     * @param $key
     * @param $parkNumber
     * @return string
     */
    private function setSign($key, $parkNumber): string
    {
        return md5($key . $parkNumber);
    }

    /**
     * post请求
     * @param $url
     * @param $param
     * @param $key
     * @param $parkNumber
     * @return mixed
     * @throws InvalidUrl
     */
    private function requestPost($url, $param, $key, $parkNumber)
    {
        $client = new HttpClient($url);
        $client->setUrl($url);
        $client->setQuery($param);
        $client->setHeaders([
            "Sign" => $this->setSign($key, $parkNumber)
        ]);
        $response = $client->post($param);
        return $response->getBody();
    }
}